﻿/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-03-03 17:00
 * 描  述：元件库文件表
 */
var refreshGirdData;
var ProjectId = parent.request('ProjectId');
var LibraryCatalogueID;
var relrtree; //初始化树形
var ShowFile;
var showLeftTree = request("showLeftTree");
var showContent;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            if (showLeftTree == "0") {
                $(".lr-layout-left").hide();
                $(".lr-layout-title").hide();
                $(".lr-layout-title").parent().addClass("lr-layout-wrap-notitle ");
                $("#lr_layout").removeClass("lr-layout-left-center");
            } else {
                //初始化tree
                relrtree();
            }

            //查询
            $('#btn_Search').on('click', function () {
                page.search($('.lr-layout-tool-left').lrGetFormData());
            });

            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                if (!LibraryCatalogueID && showLeftTree != "0") {
                    learun.alert.warning("请选择分类");
                    return;
                }
                learun.layerForm({
                    id: 'form',
                    title: '新增',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_library_file/Form?LibraryCatalogueID=' + LibraryCatalogueID + "&ProjectId=" + ProjectId,
                    width: 700,
                    height: 300,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('LibraryFileID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_library_file/Form?keyValue=' + keyValue + "&ProjectId=" + ProjectId + "&LibraryCatalogueID=" + LibraryCatalogueID,
                        width: 700,
                        height: 300,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('LibraryFileID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/ZZDT_EC/ec_library_file/DeleteForm', { keyValue: keyValue, ProjectId: ProjectId }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
            //批量导入
            $('#lr_muliteimport').on('click', function () {
                var format = 'zip,rar';
                var uploadKeyValue = Guid.NewGuid().toString();
                learun.layerForm({
                    id: 'importfile',
                    title: '批量导入',
                    url: top.$.rootUrl + '/LR_SystemModule/Annexes/UploadForm?keyVaule=' + uploadKeyValue + "&multiple=false" + "&format=" + format,
                    width: 600,
                    height: 400,
                    maxmin: true,
                    btn: ['确认'],
                    callBack: function (id) {
                        learun.layerClose('importfile');
                        MuliteImport(uploadKeyValue);
                    }
                });
            });

        },
        // 初始化列表
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_library_file/GetPageList',
                headData: [
                    {
                        label: "元件库文件名称", name: "LibraryFileName", width: 300, align: "left", sort: false,
                        formatter: function (value, row, op, $cell) {
                            return "<a style='color: #337ab7;text-decoration: underline;' href='javascript:showContent(\"" + row.LibraryFileID + "\");'>" + value + "</a>";
                        }
                    },
                    { label: '创建人', name: 'CreateUserName', width: 120, align: "center", sort: false },
                    {
                        label: "创建时间", name: "CreateTime", width: 150, align: "center", sort: false,
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
                        }
                    },
                    { label: "备注", name: "Remark", width: 300, align: "left", sort: false },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'LibraryFileID',
                sidx: "LibraryFileName",
                sord: "ASC",
                isPage: true
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.LibraryCatalogueID = LibraryCatalogueID;
            param.ProjectId = ProjectId;
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    relrtree = function () {
        // 初始化左侧树形数据
        $('#dataTree').lrtree({
            url: top.$.rootUrl + '/ZZDT_EC/ec_library_catalogue/GetTreeData',
            param: { ProjectId: ProjectId },
            nodeClick: function (item) {
                LibraryCatalogueID = item.value;
                $("#titleinfo").html(item.text);
                page.search({ LibraryCatalogueID: item.value });
            }
        });
    };
    ShowFile = function (keyValue) {
        if (learun.checkrow(keyValue)) {
            learun.layerForm({
                id: 'downform',
                title: '附件管理',
                url: top.$.rootUrl + '/LR_SystemModule/Annexes/DownForm?keyVaule=' + keyValue,
                width: $('#gridtable').width() * 0.5,
                height: $('#gridtable').width() * 0.3,
                maxmin: true,
                btn: null
            });
        }
    };
    //查看详情
    showContent = function (id) {
        if (learun.checkrow(id)) {
            learun.layerForm({
                id: 'form',
                title: '查看',
                url: top.$.rootUrl + '/ZZDT_EC/ec_library_file/Form?keyValue=' + id + '&openType=look' + "&ProjectId=" + ProjectId,
                width: 700,
                height: 260,
                btn: null
            });
        }
    };
    page.init();
}
function MuliteImport(fileId) {
    var learun = top.learun;
    learun.loading(true, "批量导入数据中...");
    $.ajax({
        type: 'POST',
        url: top.$.rootUrl + "/ZZDT_EC/ec_library_file/MuliteImport?rdo=" + Math.random(),
        data: { fileId: fileId, ProjectId: ProjectId },
        traditional: true,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.code == '200') {
                location.reload();
            }
            learun.alert.success(data.info);
        },
        error: function (msg) {
            learun.alert.error(msg);
        }, complete: function (data) {
            learun.loading(false);
        }
    });
}